﻿using System;
using System.Collections.Generic;
using System.Text;
using DotNet.Data;
using DotNet.Model;
using System.Data.SqlClient;
using System.Data;
using DotNet.Common;
namespace DotNet.Business
{
    /// <summary>
    /// 类别缓存了GetDataTable(),缓存名称GetProductClass
    /// </summary>
    public class productClassBll
    {
        productClassDal pcDal = new productClassDal();
        #region 是否存在该记录
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int pClassId)
        {
            return pcDal.Exists(pClassId);
        }
        #endregion

        #region 是否存在子类
        /// <summary>
        /// 是否存在子类
        /// </summary>
        public bool ExistsChildrens(string ClassId)
        {
            return pcDal.ExistsChildrens(ClassId);
        }
        #endregion

        #region 获得产品类别列表
        /// <summary>
        /// 获得产品类别列表
        /// </summary>
        /// <returns></returns>
        public IList<productClass> GetModel()
        {
            return pcDal.GetModel();
        }
        #endregion

        #region 根据父ID获得产品类别信息
        /// <summary>
        /// 根据父ID获得产品类别信息
        /// </summary>
        /// <returns></returns>
        public DataTable GetDataTable(int top, int fid)
        {
            return pcDal.GetDataTable(top, fid);
        }
        #endregion

        #region 获得产品类别信息
        /// <summary>
        /// 获得产品类别数据列表
        /// </summary>
        /// <returns></returns>
        public DataTable GetDataTable()
        {
            string CKey = "GetProductClass_All";
            if (CKey != "")
            {
                if (!CacheUtil.IsExist(CKey))
                {
                    CacheUtil.Insert(CKey, pcDal.GetDataTable(), 10 * 24 * 60 * 60);
                }
            }
            return CacheUtil.Read(CKey) as DataTable;

        }
        #endregion

        #region 获得父类信息
        /// <summary>
        /// 获得父类信息
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="ParentID"></param>
        /// <returns></returns>
        public DataView GetDataView(DataTable dt, int ParentID)
        {
            return pcDal.GetDataView(dt,ParentID);
        }
        #endregion


        #region 根据类别ID获得类别名称
        /// <summary>
        /// 获得父类信息
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="ParentID"></param>
        /// <returns></returns>
        public DataView GetModel(DataTable dt, int classid)
        {
            return pcDal.GetModel(dt, classid);
        }
        #endregion

        #region 根据产品类别号查询实体
        /// <summary>
        /// 根据产品类别号查询实体
        /// </summary>
        /// <param name="pClassId"></param>
        /// <returns></returns>
        public productClass GetModel(int pClassId)
        {
            string CKey = "GetProductClass_"+pClassId;
            if (CKey!= "")
            {
                if (!CacheUtil.IsExist(CKey))
                {
                    CacheUtil.Insert(CKey, pcDal.GetModel(pClassId), 10 * 24 * 60 * 60);
                }
            }
            return CacheUtil.Read(CKey) as productClass;
        }
        #endregion

        #region 修改产品类别信息
        /// <summary>
        /// 修改产品类别信息
        /// </summary>
        /// <param name="productclass"></param>
        /// <returns></returns>
        public bool Update(productClass productclass)
        {
            CacheUtil.RemoveByRegexp(@"GetProductClass_.?");
            return pcDal.Update(productclass);
        }
        #endregion

        #region 删除产品类别根据产品类别号
        /// <summary>
        /// 删除产品类别根据产品类别号
        /// </summary>
        /// <param name="pClassId"></param>
        /// <returns></returns>
        public bool Delete(int pClassId)
        {
            CacheUtil.RemoveByRegexp(@"GetProductClass_.?");
            return pcDal.Delete(pClassId);
        }
        #endregion

        #region 批量删除产品类别根据产品类别号
        /// <summary>
        /// 批量删除产品类别根据产品类别号
        /// </summary>
        /// <param name="pClassId"></param>
        /// <returns></returns>
        public bool Delete(string[] pClassid)
        {
            CacheUtil.RemoveByRegexp(@"GetProductClass_.?");
            return pcDal.Delete(pClassid);
        }
        #endregion

        #region 批量移动产品类别根据产品父类别号
        /// <summary>
        /// 批量移动产品类别根据产品父类别号
        /// </summary>
        /// <param name="pFid"></param>
        ///  <param name="classid"></param>
        /// <returns></returns>
        public bool Update(string[] pFid, string classid)
        {
            CacheUtil.RemoveByRegexp(@"GetProductClass_.?");
            return pcDal.Update(pFid, classid);
        }
        #endregion

        #region 添加产品类别
        /// <summary>
        /// 添加产品类别
        /// </summary>
        /// <param name="productclass"></param>
        /// <returns></returns>
        public bool Insert(productClass productclass)
        {
            CacheUtil.RemoveByRegexp(@"GetProductClass_.?");
            return pcDal.Insert(productclass);
        }
        #endregion
    }
}
